//    Openbravo POS is a point of sales application designed for touch screens.
//    Copyright (C) 2008-2009 Openbravo, S.L.
//    http://www.openbravo.com/product/pos
//
//    This file is part of Openbravo POS.
//
//    Openbravo POS is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    Openbravo POS is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with Openbravo POS.  If not, see <http://www.gnu.org/licenses/>.

package com.openbravo.pos.inventory;

import java.util.Properties;

import cn.ekuma.data.ui.swing.AbstractParentDAOJEditor;
import cn.ekuma.data.ui.swing.JChildDAOEditorPanel;
import cn.ekuma.epos.datalogic.I_DataLogicSales;
import com.openbravo.bean.Attribute;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.user.DirtyManager;

import com.openbravo.pos.base.AppLocal;
import com.openbravo.pos.inventory.model.AttributeValueTableModel;

/**
 *
 * @author  adrian
 */
public class AttributesEditor extends AbstractParentDAOJEditor<Attribute,String>{

    JChildDAOEditorPanel attributeValuePanel;
    private final I_DataLogicSales dlSales;

    /** Creates new form AttributesEditor */
    public AttributesEditor(I_DataLogicSales dlSales,DirtyManager dirty) {
        super(dirty);
        this.dlSales=dlSales;
        initComponents();     
        m_jName.getDocument().addDocumentListener(dirty);
        attributeValuePanel=new  JChildDAOEditorPanel(dlSales,new AttributeValueTableModel(),new AttributeValuesEditor(new DirtyManager()));
        jTabbedPane1.add(attributeValuePanel.getTabName(), attributeValuePanel);
        addObjectChangeListener(attributeValuePanel);
    }
    
    public void refresh() {
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        m_jName = new javax.swing.JTextField();
        jTabbedPane1 = new javax.swing.JTabbedPane();

        setLayout(new java.awt.BorderLayout());

        jLabel2.setText(AppLocal.getIntString("Label.Name")); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(m_jName, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(98, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(m_jName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        add(jPanel1, java.awt.BorderLayout.NORTH);
        add(jTabbedPane1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField m_jName;
    // End of variables declaration//GEN-END:variables

    @Override
    public void activate() throws BasicException {
        attributeValuePanel.activate();
    }
    // End of variables declaration

    @Override
    public Attribute createNew(Properties prop) {
        return new Attribute();
    }

    @Override
    public void rebuild(Attribute obj) throws BasicException {
        obj.setName(m_jName.getText());
    }

    @Override
    public void updateUI(boolean editAble, int state) {
        m_jName.setEditable(editAble);
        m_jName.setText(obj.getName());
    }

    @Override
    public Class getEditClass() {
        return Attribute.class;
    }


}
